package com.air.repo.design.pattern.singleton;

/**
 * Place Function on Here:
 *
 * @author yh 2018/7/12 13:36
 * @since: Jdk 1.8
 */
public class Singleton2 {

    private static final Object lock=new Object();
    private static Singleton2 instance; //申明为 private static volatile

    private Singleton2() {}

    public static Singleton2 getInstance() {
        if (instance == null) { //提高性能，不然每次getInstanace都会lock
            //T1,T2....
            synchronized (lock) {
                    instance = new Singleton2();
                }
        }
        return instance;
    }

}
